package net.demo.common.util;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

import sun.java2d.pipe.SpanShapeRenderer.Simple;

//日期操作类
public class DateUtils {
	
	public static String dateFormat(long time){
		SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		return df.format(time);
	}
	
	public static String dateFormat(long time,String regx){
		SimpleDateFormat df = new SimpleDateFormat(regx);
		return df.format(time);
	}
	
	public static String dateFormat(Date date){
		SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		return df.format(date);
	}
	
	public static String dateFormat(Date date,String regx){
		SimpleDateFormat df = new SimpleDateFormat(regx);
		return df.format(date);
	}
	
	public static Date dateFormat(String time){
		SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		try {
			return df.parse(time);
		} catch (ParseException e) {
			System.out.println("时间转换异常 请查看格式是否为'2011-05-02 12:20:22'");
			return null;
		}
	}
	

}
